package net.lab1024.sa.admin.module.business.displayModelLayer.service;

import java.util.List;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.segments.MergeSegments;
import net.lab1024.sa.admin.module.business.displayModelLayer.dao.DisplayModelLayerDao;
import net.lab1024.sa.admin.module.business.displayModelLayer.domain.entity.DisplayModelLayerEntity;
import net.lab1024.sa.admin.module.business.displayModelLayer.domain.form.DisplayModelLayerAddForm;
import net.lab1024.sa.admin.module.business.displayModelLayer.domain.form.DisplayModelLayerQueryForm;
import net.lab1024.sa.admin.module.business.displayModelLayer.domain.form.DisplayModelLayerUpdateForm;
import net.lab1024.sa.admin.module.business.displayModelLayer.domain.vo.DisplayModelLayerVO;
import net.lab1024.sa.base.common.util.SmartBeanUtil;
import net.lab1024.sa.base.common.util.SmartPageUtil;
import net.lab1024.sa.base.common.domain.ResponseDTO;
import net.lab1024.sa.base.common.domain.PageResult;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * 页面 Service
 *
 * @Author 1
 * @Date 2025-07-04 09:28:47
 * @Copyright 1
 */

@Service
public class DisplayModelLayerService {

    @Resource
    private DisplayModelLayerDao displayModelLayerDao;

    /**
     * 分页查询
     */
    public PageResult<DisplayModelLayerVO> queryPage(DisplayModelLayerQueryForm queryForm) {
        Page<?> page = SmartPageUtil.convert2PageQuery(queryForm);
        List<DisplayModelLayerVO> list = displayModelLayerDao.queryPage(page, queryForm);
        return SmartPageUtil.convert2PageResult(page, list);
    }

    /**
     * 添加
     */
    public ResponseDTO<String> add(DisplayModelLayerAddForm addForm) {
        DisplayModelLayerEntity displayModelLayerEntity = SmartBeanUtil.copy(addForm, DisplayModelLayerEntity.class);
        displayModelLayerDao.insert(displayModelLayerEntity);
        return ResponseDTO.ok();
    }

    /**
     * 更新
     *
     */
    public ResponseDTO<String> update(DisplayModelLayerUpdateForm updateForm) {
        DisplayModelLayerEntity displayModelLayerEntity = SmartBeanUtil.copy(updateForm, DisplayModelLayerEntity.class);
        displayModelLayerDao.updateById(displayModelLayerEntity);
        return ResponseDTO.ok();
    }

    /**
     * 批量删除
     */
    public ResponseDTO<String> batchDelete(List<Integer> idList) {
        if (CollectionUtils.isEmpty(idList)){
            return ResponseDTO.ok();
        }

        displayModelLayerDao.deleteBatchIds(idList);
        return ResponseDTO.ok();
    }

    /**
     * 单个删除
     */
    public ResponseDTO<String> delete(Integer id) {
        if (null == id){
            return ResponseDTO.ok();
        }

        displayModelLayerDao.deleteById(id);
        return ResponseDTO.ok();
    }

    public List<DisplayModelLayerVO> listAll() {
        List<DisplayModelLayerVO> list = displayModelLayerDao.listAll();
        return list;
    }
}
